
/*
 * Copyright (c) 2013.
 * 游戏服务器核心代码编写人陈磊拥有使用权
 * 联系方式：E-mail:13638363871@163.com ;qq:502959937
 * 个人博客主页：http://my.oschina.net/chenleijava
 */

package com.dc.gameserver.serverCore.controller.handleController.pvpCoreController;

import com.dc.gameserver.proto.gameserverprotoVo.AccpetPkRequest;
import com.dc.gameserver.proto.gameserverprotoVo.AccpetPkResponse;
import com.dc.gameserver.serverCore.controller.AbstractController.AbstractController;
import com.dc.gameserver.serverCore.controller.AbstractController.IController;
import com.dc.gameserver.serverCore.service.character.PlayerInstance;
import com.dc.gameserver.serverCore.service.cardModule.CardBoxManager;
import com.dc.gameserver.serverCore.service.managerService.PlayerManagerService;
import com.google.protobuf.MessageLite;
import org.springframework.stereotype.Service;

/**
 * @author : 石头哥哥
 *         Project : LandlordsServer
 *         Date: 13-6-4
 *         Time: 上午11:49
 *         Connect: 13638363871@163.com
 *         packageName: Server.ServerCore.Controller
 *         准备牌，通知客户端
 */
@Service
public class battleReadyController extends AbstractController {
    /**
     */
    @Override
    public void PostConstruct() {
        int ID= AccpetPkRequest.msgID.ID_VALUE;
       GAME_CONTROLLERS[ID]=this;   //业务逻辑处理引用
       IController.MESSAGE_LITE[ID]= AccpetPkRequest.getDefaultInstance();   //解析的pb实体类型
    }
     /**
     * messageLite数据结构体分发
     *
     * @param messageLite
     * @param player
     * @throws Exception
      *
      * 匹配玩家，初始化出牌数据
     */
    @Override
    public void DispatchMessageLit(MessageLite messageLite, PlayerInstance player) throws Exception {
        AccpetPkRequest accpetPkRequest=(AccpetPkRequest) messageLite;
        int givePkID=accpetPkRequest.getPlayerID();
        PlayerInstance givePkPlayer= PlayerManagerService.INTEGER_PLAYER_INSTANCE_MAP.get(givePkID);
        //通知请求挑战结果
        AccpetPkResponse.Builder builder=AccpetPkResponse.newBuilder();
        builder.setAccpet(accpetPkRequest.getAccpet());
        givePkPlayer.DirectSend(wrappedBufferShort(AccpetPkResponse.msgID.ID_VALUE,builder.build()));

        //接受挑战
        if (accpetPkRequest.getAccpet()){
            givePkPlayer.setFirstHand(true);//default first hand
            CardBoxManager.matchCardBox(player, givePkPlayer);
        }
        accpetPkRequest=null;
    }
}
